package com.kgcx.price.controller;

import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.price.domain.PriceActualPrice;
import com.kgcx.price.service.PriceActualPriceService;
import com.xiaoleilu.hutool.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "实际价格计算相关接口", tags = "实际价格计算相关接口")
@RestController
@RequestMapping("actualprice")
public class PriceActualPriceController extends BaseController {

    @Autowired
    private PriceActualPriceService priceActualPriceService;

    @ApiOperation(value = "实际价格计算接口", httpMethod = "POST", notes = "这是用来计算实际价格的接口")
    @PostMapping("caculateActualPrice")
    public ReturnData<PriceActualPrice> caculateActualPrice(@RequestBody PriceActualPrice priceActualPrice) {
        return new ReturnData<>(priceActualPriceService.caculatePrice(priceActualPrice));
    }


    @ApiOperation(value = "获取实际价格信息接口", httpMethod = "GET", notes = "这是用来获取实际价格信息的接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "orderId", required = true, value = "订单d", paramType = "query", dataType = "String")})
    @GetMapping("getPriceActualPriceByOrderId")
    public ReturnData<PriceActualPrice> getPriceActualPriceByOrderId(@RequestParam(name = "orderId") String orderId) {
        PriceActualPrice priceActualPriceByOrderId = priceActualPriceService.getPriceActualPriceByOrderId(orderId);
        if (null != priceActualPriceByOrderId) {
            Long tokenKid = this.getTokenKid();
            if (null != tokenKid) {
                if (ObjectUtil.notEqual(priceActualPriceByOrderId.getDriverId(), tokenKid) && ObjectUtil.notEqual(priceActualPriceByOrderId.getCustomerId(), tokenKid)) {
                    return ReturnData.NO_PERMISSION;
                }
            }
        }
        return new ReturnData<>(priceActualPriceByOrderId);
    }

    @ApiOperation(value = "提交其他费用、优惠券绑定接口", httpMethod = "POST",
            notes = "这是用来提交其他费用、优惠券绑定的接口 需传kid，其他费用或者优惠券id【其他费用包括：路桥费（serveiceCharge），提车费（parkingFee），其他费用（otherFee），优惠券需传优惠券Id(couponId)】")
    @PostMapping("addOtherActualPrice")
    public ReturnData<PriceActualPrice> addOtherActualPrice(@RequestBody PriceActualPrice priceActualPrice) {
        return new ReturnData<>(priceActualPriceService.addOtherActualPrice(priceActualPrice));
    }

    @ApiOperation(value = "修改使用的优惠卷", httpMethod = "POST",
            notes = "修改使用的优惠卷")
    @ApiImplicitParams({@ApiImplicitParam(name = "orderId", value = "订单id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "couponId", value = "优惠卷id", paramType = "query", dataType = "Long"),
    })
    @PostMapping("changeCoupon")
    public ReturnData changeCoupon(@RequestParam String orderId, @RequestParam Long couponId) {
        priceActualPriceService.changeCoupon(orderId, couponId);
        return new ReturnData();
    }

    @ApiOperation(value = "调价接口", httpMethod = "POST", notes = "这是用来调价的接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "orderId", value = "订单id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "price", value = "调价金额", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "adjustType", value = "调价类型 1：采用预估价 2：协商后价格 3：其他价格", paramType = "query", dataType = "Integer")})
    @PostMapping("changePrice")
    public ReturnData changePrice(@RequestParam(name = "price") String price, @RequestParam(name = "orderId") String orderId, @RequestParam(name = "adjustType") Integer adjustType) {
        priceActualPriceService.changePrice(price, orderId, adjustType);
        return new ReturnData();
    }

    @ApiOperation(value = "根据订单号查询可用价格接口", httpMethod = "GET", notes = "这是用来根据订单号查询可用价格的接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "orderIds", value = "订单列表", paramType = "query", dataType = "List")})
    @GetMapping("getTotalPriceByOrderId")
    public ReturnData<Long> getTotalPriceByOrderId(@RequestParam(name = "orderIds") List<String> orderIds) {
        return new ReturnData<>(priceActualPriceService.getTotalPriceByOrderId(orderIds));
    }


}
